home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / programming / nnn1.35 / doc / nnn.doc next >
Text File  |  1995-07-11  |  14KB  |  614 lines

  1.  
  2.  
  3.  
  4.  
  5.                nnn - Nick's Neural Network
  6.  
  7.  
  8.  
  9.                 Nicholas d'Alterio & Gideon Denby
  10.  
  11.  
  12.  
  13.                              July 11, 1995
  14.  
  15.  
  16.  
  17. Contents
  18.  
  19.  
  20. 1  Introduction                                                        2
  21.  
  22.  
  23. 2  Quickstarter                                                        2
  24.  
  25.  
  26. 3  How to use nnn                                                    2
  27.  
  28.    3.1   The Configuration File  : : : : : : : : : : : : : : : : : : : : : :   2
  29.  
  30.    3.2   Training the Neural Network : : : : : : : : : : : : : : : : : : :   5
  31.  
  32.    3.3   Classifying Unknown Vectors   : : : : : : : : : : : : : : : : : :   5
  33.  
  34.    3.4   Other Command Line Options  : : : : : : : : : : : : : : : : : :   6
  35.  
  36.    3.5   Problems : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :  *
  37.  * 6
  38.  
  39.  
  40. 4  Bugs                                                                7
  41.  
  42.  
  43. 5  History                                                             7
  44.  
  45.  
  46. 6  Release Conditions                                                8
  47.  
  48.  
  49. 7  A Quick Plug                                                      8
  50.  
  51.  
  52.  
  53.                                      1
  54. ^L
  55.  
  56.  
  57.  
  58.  
  59. 1     Introduction
  60.  
  61.  
  62. This program is an implementation of a fully connected feed forwards neural
  63.  
  64. network with error back-propagation.
  65.  
  66.    It offers the chance to train the network, which can be any size, in multiple
  67.  
  68. stages with each stage containing up to 1000 training vectors. Once trained
  69.  
  70. the network may be used to classify other vectors.  The program is fully
  71.  
  72. configurable and but simple to use.
  73.  
  74.  
  75.  
  76. 2     Quickstarter
  77.  
  78.  
  79. The configuration file included with the distribution is set up to train a neur*
  80.  *al
  81.  
  82. network with the XOR problem. To use simply type:-
  83.  
  84.  
  85.  
  86. %> nnn < nnn.conf > nnn.trained.conf
  87.  
  88.  
  89.  
  90.    This will train the neural network with the XOR vectors until 100% of the
  91.  
  92. neural networks outputs agree with the target values to within a difference
  93.  
  94. of 0.1.
  95.  
  96.    The output file will contain an updated configuration file which will now
  97.  
  98. have the final weights of the neural network stored. This can now be used to
  99.  
  100. find out what the output of any of the XOR vectors should be. This is done
  101.  
  102. by editing the configuration file and deleting the number at the end of the
  103.  
  104. line in the last four lines of the file, then run the program as follows:-
  105.  
  106.  
  107.  
  108. %> nnn -i < nnn.trained.conf > nnn.classified.conf
  109.  
  110.  
  111.  
  112.    This will print to the screen what the output of each of the vectors should
  113.  
  114. be. In addition these values will also be placed in the new configuration file
  115.  
  116. where the numbers were previously deleted.
  117.  
  118. For a list of command line options use the -h option.
  119.  
  120.  
  121.  
  122. 3     How to use nnn
  123.  
  124.  
  125.  
  126. 3.1    The Configuration File
  127.  
  128.  
  129. This section describes the format of the configuration file for the nnn pro-
  130.  
  131. gram.
  132.  
  133.    The top few lines are generally comments which describe the file purpose
  134.  
  135. and the purpose of the number below. The comment symbol is the # which
  136.  
  137.  
  138.  
  139.                                      2
  140. ^L
  141.  
  142.  
  143.  
  144.  
  145. appears at the start of a line indicating to the program that the rest of the
  146.  
  147. line may be ignored.
  148.  
  149.    The first non comment line contains the following numbers separated by
  150.  
  151. spaces:-
  152.  
  153.  
  154.  
  155.    1. The number of layer that the neural network will have.  This number
  156.  
  157.       is generally set to 3 since a three layer network with more nodes is
  158.  
  159.       generally equivalent to network with more layers. This number is not
  160.  
  161.       restricted in its maximum size but should not be less than 2. It must
  162.  
  163.       be an integer.
  164.  
  165.  
  166.    2. The learning rate for the network. This is a floating point number which
  167.  
  168.       affects how the network learns. The higher the number the faster the
  169.  
  170.       network will be trained, however this has the side effect that the initial
  171.  
  172.       behavior is erratic and the final accuracy is less.  If it is too high the
  173.  
  174.       network may never learn.  Lower numbers mean slower training but
  175.  
  176.       more accurate results. The standard value used during test was 2.0
  177.  
  178.  
  179.    3. The gain factor. This is a floating point number which affects the slope
  180.  
  181.       of the sigmoid function, the higher the number the greater the slope.
  182.  
  183.       Increasing this may improve the network performance however taking
  184.  
  185.       it too high will cause the sigmoid to quickly saturate. Set this equal to
  186.  
  187.       1.0 for standard neural network.
  188.  
  189.  
  190.    4. The momentum factor this is a floating point number in the range 0 to
  191.  
  192.       1. Its purpose is to keep the network moving towards its final answer.
  193.  
  194.       It has the potential to vastly increase the rate of convergence but may
  195.  
  196.       also introduce extra local minima.  Set the momentum factor to zero
  197.  
  198.       to go back to a tradition back propagation neural network.
  199.  
  200.  
  201.    5. A seed for the random number generator.
  202.  
  203.  
  204.    6. The accuracy that the neural network must achieve for the program to
  205.  
  206.       decide that it has learnt a particular vector correctly. This is a floati*
  207.  *ng
  208.  
  209.       point number in the range 0 to 1, the smaller the number the more
  210.  
  211.       accurate.
  212.  
  213.  
  214.    7. The percentage of vectors that the network must learn before stopping
  215.  
  216.       the training process.
  217.  
  218.  
  219.  
  220.    All the above options except for the number of layers may be overridden
  221.  
  222. by command line options.
  223.  
  224.  
  225.  
  226.                                      3
  227. ^L
  228.  
  229.  
  230.  
  231.  
  232.    Next in the file is a marker #Layers  which indicates that information
  233.  
  234. about the network size follows. There must be as many lines as specified in
  235.  
  236. the previous section number of layers.
  237.  
  238.    Each line should contain an integer which is the number of nodes that
  239.  
  240. particular layer in the network will contain with the top line being the input
  241.  
  242. of the neural network.  It is important that the number of nodes on the
  243.  
  244. input layer and the number of nodes on the output layer match the number
  245.  
  246. of inputs and outputs in the training vectors that will be applied to the
  247.  
  248. network. There is no limitation on the size of the number here.
  249.  
  250. e.g.
  251.  
  252.  
  253.  
  254. #Layers                    Marker
  255.  
  256. 2                           Number of nodes in input layer
  257.  
  258. 2                           Number of nodes in hidden layer
  259.  
  260. 1                           Number of output nodes
  261.  
  262.  
  263.  
  264.    If the network has not been previously trained the next marker will be
  265.  
  266. #Vectors otherwise it will be #Weights which will be followed by the a single
  267.  
  268. line containing all the weights obtained during training.  This is generated
  269.  
  270. by the program.
  271.  
  272.    The the end of the file in therefore always marked by the #Vectors marker
  273.  
  274. which is followed by a number of lines each containing one vector. A vector
  275.  
  276. consists of a bias, the input vector, and the expected outputs for that input
  277.  
  278. vector. There is a limit of 1000 vectors in any run of the program.
  279.  
  280.    The biases are extra normalising nodes for the neural network to prevent
  281.  
  282. the output from getting out of control.  Each layer of the network has one
  283.  
  284. bias node and its value is given by the bias of the first vector, in addition t*
  285.  *he
  286.  
  287. other vectors may have independent biases.  In normal operation all biases
  288.  
  289. are set to -1.
  290.  
  291. e.g.
  292.  
  293.  
  294.  
  295. #Vectors
  296.  
  297. -1                 0     0                0
  298.  
  299. -1                 0     1                1
  300.  
  301. -1                 1     0                1
  302.  
  303. -1                 1     1                0
  304.  
  305. bias          input vectors    expected output
  306.  
  307.  
  308.  
  309.    NOTE The program currently does not have much error checking when
  310.  
  311. parsing the configuration file. Therefore the user must ensure that the file is
  312.  
  313. exactly as described above or there may be unpredictable results.
  314.  
  315.  
  316.  
  317.                                      4
  318. ^L
  319.  
  320.  
  321.  
  322.  
  323. 3.2    Training the Neural Network
  324.  
  325.  
  326. To train the neural network first choose the network parameters and con-
  327.  
  328. struct a configuration file with the training vectors at the bottom. Then run
  329.  
  330. the program with the command:-
  331.  
  332.  
  333.  
  334. %> nnn < nnn.conf > new.nnn.conf
  335.  
  336.  
  337.  
  338.    The program will then begin to train the network to the desired level of
  339.  
  340. accuracy.  If the network succeeds in the training it will print a message to
  341.  
  342. the screen describing the percentage of vectors classified correctly and the
  343.  
  344. number of iterations that it took to achieve it.  If the network fails then a
  345.  
  346. message will be printed stating the final classification level.
  347.  
  348.    In both cases the weights will be saved in the file new.nn.conf which can
  349.  
  350. then be used for classifying unknown vectors or further training.
  351.  
  352.    An alternative to printing a configuration file is to print a graph of ac-
  353.  
  354. curacy against number of iterations. This is done with the -g command line
  355.  
  356. option.
  357.  
  358.    NOTE The network will only classify output nodes to be either 0 or 1
  359.  
  360. so to train a neural network with a data set which has 2n possible outcomes
  361.  
  362. there must be n output nodes.
  363.  
  364.  
  365.  
  366. %> nnn -g < nnn.conf > graph.file
  367.  
  368.  
  369.  
  370. 3.3    Classifying Unknown Vectors
  371.  
  372.  
  373. For this it is necessary to have a configuration file containing the weights at
  374.  
  375. the end of training.  Edit this file and replace the vectors section with the
  376.  
  377. set of biases and inputs that need to be classified. Then run the program as
  378.  
  379. usual with the -m command line option.
  380.  
  381.  
  382.  
  383. %> nnn -i < nnn.trained.conf > nnn.classified.conf
  384.  
  385.  
  386.  
  387.    This will classify each output node to be either 0 or 1 depending on the
  388.  
  389. values after the vector to be classified has been fed through the network.
  390.  
  391. These values will be printed both to the screen and to the file so that they
  392.  
  393. follow the input part of the vector.
  394.  
  395.    If no weights are present in the configuration file the program will print
  396.  
  397. a message and exit.
  398.  
  399.  
  400.  
  401.                                      5
  402. ^L
  403.  
  404.  
  405.  
  406.  
  407. 3.4    Other Command Line Options
  408.  
  409.  
  410. In addition to the command line options already mentioned there are a few
  411.  
  412. command line options which enable the user to change the network settings
  413.  
  414. without editing the configuration file. These are of the form
  415.  
  416.  
  417.  
  418. %> nnn -s 1024 < nnn.conf > nnn.new.conf
  419.  
  420.  
  421.  
  422.    The above example sets the seed to be 1024. These command line options
  423.  
  424. override any values found within the configuration file. They include:-
  425.  
  426.  
  427.  
  428. -r sets the learning rate
  429.  
  430.  
  431. -m  sets the momentum factor
  432.  
  433.  
  434. -s sets the seed for the random number generator
  435.  
  436.  
  437. -a sets desired accuracy for network to attain
  438.  
  439.  
  440. -c sets the percentage of vectors to classify correctly
  441.  
  442.  
  443. -k sets the gain factor
  444.  
  445.  
  446.  
  447. 3.5    Problems
  448.  
  449.  
  450. There may be occasions where the neural network will not converge towards
  451.  
  452. the expected output and there are often many reasons for this. This section
  453.  
  454. will attempt to make some suggestions to improve the chances of correct
  455.  
  456. training.
  457.  
  458.  
  459.  
  460.    1. Use the -g option to see how the training proceeds.
  461.  
  462.  
  463.    2. Try changing the learning rate. A low learning rate may become stuck
  464.  
  465.       in a local minima whilst a high rate may never settle down.
  466.  
  467.  
  468.    3. Adjust the momentum factor. This may increase the speed of conver-
  469.  
  470.       gence of the network.
  471.  
  472.  
  473.    4. It may be that the random series generated by the seed gets the network
  474.  
  475.       stuck.
  476.  
  477.  
  478.    5. Think about reducing the accuracy that is expected from the network,
  479.  
  480.       there will be situations where it is just not possible to get very accura*
  481.  *te
  482.  
  483.       results.
  484.  
  485.  
  486.  
  487.                                      6
  488. ^L
  489.  
  490.  
  491.  
  492.  
  493.    6. Reduce the percentage of vectors that is expected to be classified cor-
  494.  
  495.       rectly during training.  It is often the case that all but a couple of
  496.  
  497.       vectors will classify.
  498.  
  499.  
  500.    7. When using binary vectors try having 0 as 0.1 and 1 as 0.9 this moves
  501.  
  502.       the output away from the flat area on the sigmoid function and increase
  503.  
  504.       the chance of convergence.
  505.  
  506.  
  507.    8. It may be that there are not enough hidden nodes to correctly define
  508.  
  509.       the problem. Increasing the number of hidden nodes generally speeds
  510.  
  511.       up convergence to the correct output.
  512.  
  513.  
  514.    9. Do NOT expect to train to get an output of greater than one. This is
  515.  
  516.       outside the range of the sigmoid and will therefore NEVER be success-
  517.  
  518.       ful.
  519.  
  520.  
  521.   10. If the sigmoid is saturating make this value small so that the slope is
  522.  
  523.       decreased.
  524.  
  525.  
  526.   11. As a last resort it may be worth adjusting the value of the biases
  527.  
  528.       however this is not recommended.
  529.  
  530.  
  531.  
  532.    There are cases where this type of neural network is not appropriate and
  533.  
  534. there are certainly cases where this is not the best solution so experiment a
  535.  
  536. bit.
  537.  
  538.  
  539.  
  540. 4     Bugs
  541.  
  542.  
  543. At present there are no known bugs.  However there are circumstances in
  544.  
  545. which the program will crash if not used correctly.
  546.  
  547.    For example if an option which requires a numeric argument is used with-
  548.  
  549. out the argument a non-existent array element will be accessed.
  550.  
  551.    If the program is used as detailed in this document there will be no
  552.  
  553. problems.
  554.  
  555.    If you find a bug or edit this program please send details to n.dalterio@ic.*
  556.  *ac.uk
  557.  
  558.  
  559.  
  560. 5     History
  561.  
  562.  
  563. This is out third attempt at writing a neural network program and was
  564.  
  565. designed to be easy to read and understand unlike all other neural network
  566.  
  567. programs we have managed to obtain in source form.
  568.  
  569.  
  570.  
  571.                                      7
  572. ^L
  573.  
  574.  
  575.  
  576.  
  577.    The main reason for the problems in getting a working neural network
  578.  
  579. program originate with poorly written books on the subject which don't
  580.  
  581. make there notation clear and consequently have impossible to understand
  582.  
  583. algorithms.
  584.  
  585.    In addition there are many points which are not mentioned in books but
  586.  
  587. are essential to getting the program to work correctly.
  588.  
  589.  
  590.  
  591. 6     Release Conditions
  592.  
  593.  
  594. There are none, but I accept no responsibility for things that may happen
  595.  
  596. because to its use.
  597.  
  598.  
  599.  
  600. 7     A Quick Plug
  601.  
  602.  
  603. This program was created as part of a project for my Physics degree , for the
  604.  
  605. full report and other work I have done see
  606.  
  607.  
  608.  
  609. http://crab.sp.ph.ic.ac.uk/"projects/nick_gid/index.html
  610.  
  611.  
  612.  
  613.                                      8
  614.